<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


<script>

    let p1 = {
        name: 'Tom',
        age: 12,
        gender: 'male'
    }

    let p2 = {
        name: 'Jerry',
        age: 13,
        hobby: ['抽烟','喝酒','烫头']
    }

    let p3 = {
        name: '刘备',
        age: 30,
        partner: [
            {name:'关羽',age:28},
            {name:'张飞',age:25}
        ]
    }

    //json转换为字符串
    let jsonStr = JSON.stringify(p3);
    console.log(jsonStr);
    console.log(typeof jsonStr);

    //将字符串转化json
    let jsonObj = JSON.parse(jsonStr);
    console.log(jsonObj);
    console.log(typeof jsonObj);


</script>
</body>
</html>